using System;
using NUnit.Framework;

[TestFixture]
public class TestAndand {
    private class D {}
    private class C {
        public D d;
    }
    private class B {
        public C c;
    }
    private class A {
        public B b;
    }
    [Test]
    public void andand() {
        A nil = null;
        A a = new A();
        A ab = new A() { b = new B() };
        Assert.IsNull(AA.Andand<A>(() => null));
        Assert.IsNull(AA.Andand(() => (A)null));
        Assert.AreEqual(a, AA.Andand(() => a));
        Assert.IsNull(AA.Andand(() => a.b));
        Assert.AreEqual(ab.b, AA.Andand(() => ab.b));
        Assert.IsNull(AA.Andand(() => ab.b.c));
        Func<Object> x = null;
        Func<Func<Object>> y = null;
        y = () => null;
        Assert.IsNull(AA.Andand(() => y()()));
        Assert.IsNull(AA.Andand(() => a.b.c));
        Assert.IsNull(AA.Andand(() => a.b.c.d));
    }
}
